Skip to content

Runs always end: PR before the checks, rounds that survive continuations, and a ceiling on every run - #485

Merged
nambok merged 2 commits into
mainfrom
fix/run-loop-guard
Nov 5, 2026
Merged

nambok merged 2 commits into
mainfrom
fix/run-loop-guard

Conversation

@nambok

@nambok nambok commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A small ticket finished all its tasks, then spent hours and a large amount of spend without opening a pull request. This changes the design so that can't recur. The draft pull request now opens as soon as the work is built, and the checks run on it. A check runs once on a head. A run with no real progress is handed to a person, and every run has an absolute ceiling held in layers that don't depend on each other.

Root cause

  • passes/mod.rs run_passes: the only gate for the checks was Gate::Checks, and it came before the pull request, so every step resumed there and re-ran all of them. The pull request came last, with whatever time was left.
  • proof.rs prove, feature/mod.rs gate, link_checks.rs gate, test_fix.rs gate: let mut rounds = 0 was a local, so each step had new fix rounds.
  • feature/mod.rs and test_fix.rs fix rounds passed None as their deadline, so a round ran until the time limit cut the whole step off.
  • steps.rs stalled_after counts a moved branch head as progress, and every fix is a commit, so the stall stop never fired. Only the 50-step ceiling applied.

Earlier fixes, and why the problem survived them

Change What it did Gap Closed here by
#214 Stopped the CI wait loop after about a day Only that wait loop The ceiling covers every message kind
#235 No-op fix cycles count as stalled A fix that commits isn't a no-op Progress no longer means a commit
#331 Plan check before the PR; rounds get their own budget The budget is per round, and the PR still came after the checks PR first; rounds counted per run
#357 Runs keep going while they make progress, replacing the fixed limits of 3 continuations and 45 minutes This is what made the loop unbounded: head moved means progress, and a resumed step re-ran the checks Progress redefined; the ledger keeps results across steps
#368 Planning continues at its own gate with a persisted state Planning only The same idea, applied to the checks
#477 At most two fix rounds on the own review One loop, and the proof and rule checks kept local counters Every check's rounds are in the run's ledger

This does not close one gap: a run that really makes progress forever on a very large ticket is only stopped by the absolute ceiling, not by the no-progress guard. That is intended.

Limits (all in run_guard.rs and run_ceiling.rs)

Limit Value Why
Proof fix rounds per run 2 Same as #477; a round with no fewer gaps ends them at once
New-feature-rule fix rounds per run 2 Same
Link fix rounds per run 1 Unchanged, now per run
Failing-test fix rounds per run 2 Unchanged, now per run
Continuations once tasks are done 3 Opening the PR and checking it take one step
Continuations without progress 6 One task over 90 minutes of steps
Pass transitions without progress 40 Worst case the caps allow between two progress events is 35 (worst_normal_run)
Spend without progress $20 About five full steps at about $4 each
Ceiling: passes 300 Three times the 50-step ceiling
Ceiling: continuations 50 The existing step ceiling
Ceiling: worked time 16 hours 50 steps of 15 minutes is 12.5 hours, plus rounds on the PR
Ceiling: spend $200 50 steps at about $4

These are sized from the code's own caps and a typical cost per step. They are not sized from recorded run histories: the production read was refused by the permission system, and the repository's fixtures only hold short runs. The real distribution should be checked against them before relying on the ceilings as tight.

The run's shape, replayed (incidents/p_finished_work_loop.rs): with the guard alone it stops at its fourth continuation, at about a third of the original spend. With no word that its tasks were done, the spend limit stops it a few steps later ($20 since the last real progress). The per-step cost is the total divided by the steps, since only the total was recorded. With the new order, the pull request is open before any of those checks run.

Behaviour that relied on checks before the PR

  • New-feature rules, link checks and failing-test rules used to stop the PR. They now list what failed under Open items with a mark that holds the draft (draft_hold).
  • A failing-test tooling failure used to fail the run with its kind recorded. It is now an Open item in its own words, and the run no longer records stop_kind for it.
  • The description is written before the checks. Their results reach it deterministically (pr::apply_checks), but the writer no longer sees them, including the failing-test evidence for a small test fix's four-section description.
  • Fix rounds now push to an open PR, so each one triggers CI.

Kept before the PR, on purpose

  • The search for someone else's open PR (stop_gate::existing_work): it exists to avoid a second PR.
  • The generator check, the adversarial test and the security audit: these aren't on the list that moved, and none of them can block the PR. There is no separate build step before the PR; CI runs the build on it.

What can't be done exactly as asked

  • Wall-clock ceiling: it counts time the worker spent on the run, not calendar time. A calendar limit would end PRs rightly waiting days for CI or a person.
  • A person's comment on a run over its ceiling doesn't run: only Retry starts a new allowance, as asked. Below the ceiling, a comment clears the no-progress stop.
  • The sweep notes the PR or branch rather than opening a draft: that lambda has no GitHub access.
  • A fresh ticket's first step adds no worked time, because its run id doesn't exist at entry. Its passes and spend are still counted.
  • A model call in a task spawned outside the message's task isn't held by the allowance. The one spawn found in the run path writes progress notes and makes no model call.

Changes

  • run_guard.rs (new): the no-progress guard, called from update_pass, try_auto_continue and implement::run, so a later pass is covered. Holds the per-run ledger of checks. One ending: draft with Open items, needs_input, a plain reason, one notification, loop_stop_reason recorded, and a run_loop_stopped log line with a metric filter.
  • run_ceiling.rs (new): lifetime counts on the run record, the entry guard at the worker's one entry point, and the step's model allowance.
  • common/messages.rs: WorkerMessage::run_ref has no catch-all, so a new message kind doesn't compile until it says whether it belongs to a run.
  • common/usage.rs: UsageMeter::admit refuses once the run's allowance is spent or closed. model_call_sites already fails the build for a model call that skips admit.
  • lambda/stuck-run-cleanup: ends any run over its ceiling, from outside the worker, whatever its last update says.
  • steps.rs: new Gate::Pr before Gate::Checks; an in-flight run at the old checks gate with no PR goes to the PR first. Continuations no longer write fake plan and implement passes.
  • mod.rs: single and multi repository paths open the PR first. proof.rs, feature, link_checks.rs and test_fix.rs: results and rounds in the ledger by head; every fix round stops at the step's deadline.
  • Gateway analytics: loops_stopped, by reason. Dashboard pin moves to the run steps and analytics change.

Every loop in the run path

Loop Covered by
Time-limit continuations try_auto_continue: guard and ceiling
Model-error retries Existing retry policy; the entry guard and resume_run_to_running refuse a stopped run
Plan check rounds update_pass, implement::run, continuation limits
Proof, rules, links, failing tests Ledger rounds, plus the guard
Generators, test and security fixes update_pass, implement::run
CI fix loop MAX_AUTO_FIX_PUSHES and MAX_CI_FIX_CYCLES, plus update_pass
Feedback, CI only claim_auto_fix_slot, plus on_pass
Feedback from a person Resets the no-progress guard; the ceiling still holds
Own review Its own two rounds, plus update_pass
Conflict rounds and planned-work rounds Their round attempts, plus update_pass
pr::resolve_conflicts before the PR Bounded by its own model calls and the step's time; a model call is held by the allowance

Verification

  • cargo fmt --all --check and cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p worker -p common -p gateway: worker 1267 passed, common 1429 and 2, gateway 731, 0 failed.
  • python3 -m unittest discover -s lambda/tests: 354 passed, 0 failed.
  • Dashboard: lint, typecheck, check:openapi, and run-steps, audit-runs and analytics Playwright specs (39 passed). The full suite is left to CI.
  • infra was not run locally for the new metric filter; left to CI.

How each layer was tested. incidents/q_run_ceiling.rs drives the real run_ceiling::admit and the real UsageMeter::admit with an adversarial handler that always sends the run back, for each run message kind and every pass, against an in-memory record. Each layer is removed in turn and the others still end the run within the ceiling; with all removed it never ends, so the test can fail. The sweep's own code is tested in Python, including its handler against a fake table; in the Rust test it is the same decision, not the Python.

Not verified. None of this has run against real AWS or a real run: the orchestration in run_passes is covered by source-structure tests and the pure logic it calls, not an end-to-end run. No deploy.

@nambok
nambok merged commit 593d8ed into main Nov 5, 2026
10 checks passed
@nambok
nambok deleted the fix/run-loop-guard branch November 5, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant